<template>
  <el-input-number v-model="value" v-bind="fieldProps" :placeholder="placeholder"></el-input-number>
</template>

<script setup name="RNumber">

import {ref, watch} from "vue";

const emit = defineEmits(['update:modelValue'])

const props = defineProps({
  modelValue: [String, Number],
  fieldProps: Object,
  placeholder: String
})

const value = ref()

watch(() => props.modelValue, () => {

  //string转为number， 去除警告
  if (props.modelValue) {
    if (typeof props.modelValue === 'string') {
      value.value = parseInt(props.modelValue)
    } else {
      value.value = props.modelValue
    }
  }

}, {immediate: true})

watch(value, () => {
  emit('update:modelValue', value.value)
})

</script>

<style scoped>

</style>
